
package trabalho.xml.gui;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Random;

import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DlgTarefa extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Label label1;
	private Button button1;
	private Text txtNumero;
	public String strNumero;
	public boolean estado;
	public ArrayList<Integer> m_listaNumero;
	

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			DlgTarefa inst = new DlgTarefa(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public DlgTarefa(Shell parent, int style) {
		super(parent, style);
		//m_listaNumero = new LinkedList<Integer>(); 
	}

	public void geraNumeros (String stringQuantidade){ 
		int quantidade = Integer.parseInt(stringQuantidade);
		m_listaNumero = new ArrayList<Integer>();
		Random geraNumero = new Random(); 
		for (int i=0;i<quantidade;i++){ 
			m_listaNumero.add(geraNumero.nextInt(quantidade));
		}
	}

	public boolean open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			dialogShell.setLayout(new FormLayout());
			dialogShell.layout();
			dialogShell.pack();			
			dialogShell.setSize(299, 218);
			estado = false;
			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				FormData button1LData = new FormData();
				button1LData.left =  new FormAttachment(0, 1000, 226);
				button1LData.top =  new FormAttachment(0, 1000, 145);
				button1LData.width = 26;
				button1LData.height = 23;
				button1.setLayoutData(button1LData);
				button1.setText("OK");
				button1.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						System.out.println("button1.widgetSelected, event="+evt);
						//TODO add your code for button1.widgetSelected
						geraNumeros(txtNumero.getText());
						estado = true;
						dialogShell.close();
					}
				});
			}
			{
				FormData text3LData = new FormData();
				text3LData.left =  new FormAttachment(0, 1000, 86);
				text3LData.top =  new FormAttachment(0, 1000, 90);
				text3LData.width = 98;
				text3LData.height = 18;
				txtNumero = new Text(dialogShell, SWT.NONE);
				txtNumero.setLayoutData(text3LData);
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				FormData label1LData = new FormData();
				label1LData.left =  new FormAttachment(0, 1000, 12);
				label1LData.top =  new FormAttachment(0, 1000, 12);
				label1LData.width = 259;
				label1LData.height = 44;
				label1.setLayoutData(label1LData);
				label1.setText("\t Escolha a quantidade  de numeros \n                         que deseja ordenar:");
			}
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return estado;
	}
	
}
